package com.donfu.web.controller.house;

import java.util.List;

import com.donfu.system.domain.dto.HouseProductTypeDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.enums.BusinessType;
import com.donfu.system.domain.house.HouseProductType;
import com.donfu.system.service.house.IHouseProductTypeService;
import com.donfu.common.utils.poi.ExcelUtil;
import com.donfu.common.core.page.TableDataInfo;

/**
 * 产品类型Controller
 * 
 * @author donfu
 * @date 2021-12-01
 */
@Api(tags = "后台--商品分类")
@RestController
@RequestMapping("/house/productType")
public class HouseProductTypeController extends BaseController
{
    @Autowired
    private IHouseProductTypeService houseProductTypeService;

    /**
     * 查询产品类型列表
     */
    @ApiOperation("查询产品类型列表")
    @PreAuthorize("@ss.hasPermi('house:productType:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseProductType houseProductType)
    {
        startPage();
        List<HouseProductType> list = houseProductTypeService.selectHouseProductTypeList(houseProductType);
        return getDataTable(list);
    }

    /**
     * 查询商品分类以树形结构返回
     */
    @ApiOperation("查询商品分类以树形结构返回")
    @PreAuthorize("@ss.hasPermi('house:productType:list')")
    @GetMapping("/getTypeTree")
    public TableDataInfo getProductTypeTree()
    {
        List<HouseProductTypeDTO> list = houseProductTypeService.getProductTypeTree();
        return getDataTable(list);
    }


    /**
     * 导出产品类型列表
     */
    @ApiOperation("导出产品类型列表")
    @PreAuthorize("@ss.hasPermi('house:productType:export')")
    @Log(title = "产品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HouseProductType houseProductType)
    {
        List<HouseProductType> list = houseProductTypeService.selectHouseProductTypeList(houseProductType);
        ExcelUtil<HouseProductType> util = new ExcelUtil<HouseProductType>(HouseProductType.class);
        return util.exportExcel(list, "产品类型数据");
    }

    /**
     * 获取产品类型详细信息
     */
    @ApiOperation("获取产品类型详细信息")
    @ApiImplicitParam(name = "id",value = "商品信息ID", dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('house:productType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseProductTypeService.selectHouseProductTypeById(id));
    }

    /**
     * 新增产品类型
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('house:productType:add')")
    @Log(title = "产品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseProductType houseProductType)
    {
        return toAjax(houseProductTypeService.insertHouseProductType(houseProductType));
    }

    /**
     * 修改产品类型
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('house:productType:edit')")
    @Log(title = "产品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseProductType houseProductType)
    {
        return toAjax(houseProductTypeService.updateHouseProductType(houseProductType));
    }

    /**
     * 删除产品类型
     */
    @ApiOperation("删除")
    @ApiImplicitParam(name = "ids",value = "商品信息Id集合", dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('house:productType:remove')")
    @Log(title = "产品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseProductTypeService.deleteHouseProductTypeByIds(ids));
    }
}
